package com.llyb.tingshu.order.config;

import com.llyb.tingshu.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;


@Configuration
public class CanalOrderMqConfig {

    @Bean
    public Queue canalOrderQueue(){
        return new Queue(MqConst.QUEUE_CANCEL_ORDER, true, false, false);
    }

    @Bean
    public CustomExchange canalOrderExchange(){
        // 设置参数
        HashMap<String, Object> hashMap = new HashMap<>();

        hashMap.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER, "x-delayed-message", true, false, hashMap);
    }

    @Bean
    public Binding canalOrderBinding(){
        return BindingBuilder.bind(canalOrderQueue()).to(canalOrderExchange()).with(MqConst.ROUTING_CANCEL_ORDER).noargs();

    }
}
